home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1997 February / PC Shareware 1997-02.iso / programy / e! / api / briefkey.c_ / briefkey.C
Encoding:
C/C++ Source or Header  |  1995-03-05  |  3.7 KB  |  129 lines

  1. /*-------------------------------------------------
  2.    BRIEFKEY.C -- Extension DLL for E! - version 1.0
  3.  
  4.    To compile: nmake /f briefkey.mak
  5.  
  6.    Once compiled, copy BRIEFKEY.EWD to your USER directory.
  7.  
  8.    To use this DLL simply load it from the user menu or add its name to the
  9.    list of autoloaded Extension DLLs by using the Autoload dialog box from
  10.    the User Menu of E!. That's all.
  11.  
  12.    BRIEFKEY emulates the behavior of the Home/End keys in the Brief editor.
  13.    If you press the END key once, the cursor moves to the end of the current line.
  14.    Pressing it a second time moves it to the end of the current page, and pressing
  15.    it a third time moves it to the end of the file.  Home works similarly in the
  16.    reverse direction. If you use another function key, this process is reset.
  17.  
  18.   ------------------------------------------------*/
  19.  
  20. #include <windows.h>
  21. #include "ewapi2.h"
  22.  
  23.  
  24. static int  nHome  = 0;
  25. static int  nEnd   = 0;
  26.  
  27. int FAR PASCAL _export FuncEntryHook(unsigned int command)
  28. {
  29.   static BOOL bInUse = FALSE;
  30.  
  31.   if (!bInUse)
  32.   // We need a reentrancy flag because the calls to EWTopOfPage and to
  33.   // EWTopOfText would cause the keystroke counter to be reset: FuncEntryHook
  34.   // will be called for ALL editing functions.
  35.   {
  36.     bInUse = TRUE;
  37.     if (command == ew_BeginLine)
  38.     {
  39.       nEnd = 0;
  40.       switch (nHome)
  41.       {
  42.         case 0:               // First keystroke
  43.           EWBeginLine( 0 );   // Don't use the default, because we want to
  44.           nHome++;            // stay on the current line if already at BOL
  45.           bInUse = FALSE;
  46.  
  47.           return (1);         // We don't allow the standard function to be executed
  48.  
  49.         case 1:               // Second keystroke
  50.           EWTopOfPage(1);
  51.           nHome++;
  52.           bInUse = FALSE;
  53.           return (1);         // We don't allow the standard function to be executed
  54.  
  55.         case 2:               // Third keystroke
  56.           EWTopOfText(1);
  57.           nHome = 0;
  58.           bInUse = FALSE;
  59.           return (1);         // We don't allow the standard function to be executed
  60.       }
  61.     }
  62.     else
  63.       nHome = 0;              // Otherwise reset counter
  64.  
  65.     if (command == ew_EndLine)
  66.     // We must check for both commands anyway to be sure to correctlt reset
  67.     // the counters. For example if we hit Home twice and then hit the End key.
  68.     {
  69.       nHome = 0;
  70.       switch (nEnd)
  71.       {
  72.         case 0:
  73.           nEnd++;
  74.           EWEndLine( 0, 0 );  // Don't use the default because we want to stay
  75.           bInUse = FALSE;     // where we are if we are already at EOL
  76.  
  77.           return (1);         // We don't allow the standard function to be executed
  78.  
  79.         case 1:
  80.           EWTopOfPage(0);
  81.           EWEndLine( 0, 0 );  // make sure that we are still at EOL
  82.           nEnd++;
  83.           bInUse = FALSE;
  84.           return (1);
  85.  
  86.         case 2:
  87.           EWTopOfText(0);
  88.           nEnd = 0;
  89.           bInUse = FALSE;
  90.           return (1);
  91.       }
  92.     }
  93.     else
  94.       nEnd = 0;
  95.  
  96.     bInUse = FALSE;
  97.   }
  98.   return (0); // Standard behavior
  99. }
  100.  
  101. int FAR PASCAL _export NotifyHook(unsigned int code, unsigned int wParam, long lParam)
  102. {
  103.   if (code == EWNotify_ActWinChanged)
  104.   {
  105.     nHome = 0;
  106.     nEnd = 0;
  107.   }
  108. }
  109.  
  110. int FAR PASCAL _export _WEP(int nParameter)
  111. {
  112.   // Remove hook before unloading
  113.   EWRemoveHook(EWHook_FunctionEntry, FuncEntryHook);
  114.   EWRemoveHook(EWHook_Notify, NotifyHook);
  115.   return (1);
  116. }
  117.  
  118. int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
  119. {
  120.  
  121.   if (wHeapSize > 0)
  122.     UnlockData (0) ;
  123.   // Install hook on function entry
  124.   EWSetHook(EWHook_FunctionEntry, FuncEntryHook);
  125.   EWSetHook(EWHook_Notify, NotifyHook);
  126.   return (1) ;
  127. }
  128.  
  129.